﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Drawing2D;
using System.Drawing;

namespace WebKpiPage.Data.util
{
    public struct Rect
    {
        public double x1;
        public double y1;
        public double x2;
        public double y2;
    }

    public class RegionExtern
    {
        // 坐标缩放因子[因为graphics的 IsVisible 方法在判定经纬度时,需要放大计算]
        private static float zoom_factor = 10000;

        public Rect Bounds;

        private GraphicsPath _region = new GraphicsPath();

        public void SetPolygon(PointF[] points)
        {
            try
            {
                for (int i = 0; i < points.Length; i++)
                {

                    points[i].X *= zoom_factor;
                    points[i].Y *= zoom_factor;
                }
                _region.AddPolygon(points);

                RectangleF rect = _region.GetBounds();

                Bounds.x1 = rect.X / zoom_factor;
                Bounds.y1 = rect.Y / zoom_factor;

                Bounds.x2 = rect.Right / zoom_factor;
                Bounds.y2 = rect.Bottom / zoom_factor;

            }
            catch (System.Exception ex)
            {
                throw ex;
            }

        }

        public bool PtInRegion(float x, float y)
        {
            bool ret = _region.IsVisible(x * zoom_factor, y * zoom_factor);
            return ret;
        }
    }
}
